package com.wg.net.operations;

import com.wg.core.io.BigEndianBinaryReader;
import com.wg.core.io.BigEndianBinaryWriter;
import com.wg.core.io.IBinaryReader;
import com.wg.core.io.IBinaryWriter;
import com.wg.core.io.IBinaryReadable;
import com.wg.core.io.IBinaryWritable;
import com.wg.net.operations.base.OperationRequest;

public class PingRequest implements IBinaryWritable, IBinaryReadable {

    private long clientTimeStamp;

    public PingRequest(long clientTimeStamp) {
        this.clientTimeStamp = clientTimeStamp;
    }

    public PingRequest(OperationRequest operationRequest) {
        readBytes(new BigEndianBinaryReader(operationRequest.getBuffer()));
    }

    public long getClientTimeStamp() {
        return clientTimeStamp;
    }

    public void setClientTimeStamp(long clientTimeStamp) {
        this.clientTimeStamp = clientTimeStamp;
    }

    @Override
    public void readBytes(IBinaryReader reader) {
        clientTimeStamp = reader.readLong();
    }

    @Override
    public byte[] toBytes() {
        IBinaryWriter writer = new BigEndianBinaryWriter(16);
        writer.writeLong(clientTimeStamp);
        return writer.toByteArray();
    }
}
